/**
 * @author wItspirit
 * 28-mei-2005
 * DefaultReusableUIFactory.java
 */

package org.scohen.juploadr.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.DeviceData;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

/**
 * This is the default implementation of the ReusableUIFactory.
 */
public class DefaultReusableUIFactory extends ReusableUIFactory {
    private static final String UNKNOWN_RESOURCE = "org/scohen/juploadr/resources/unknown.png";
    private static final String TINYLOGO_RESOURCE = "org/scohen/juploadr/resources/icon.png";
    private static final String LOGO_RESOURCE = "org/scohen/juploadr/resources/logo.png";
    private static final String UPLOADED_RESOURCE = "org/scohen/juploadr/resources/uploaded.png";
    private static final String ROTATE_RIGHT_IMAGE = "org/scohen/juploadr/resources/rotate_right.png";
    private static final String ROTATE_LEFT_IMAGE = "org/scohen/juploadr/resources/rotate_left.png";
    private static final String UPLOADING_RESOURCE = "org/scohen/juploadr/resources/upload.png";
    private static final String PHOTOSET_IMAGE = "org/scohen/juploadr/resources/sets.png";

    private Display display;

    private Image uploadingImage;
    private Image uploadedImage;
    private Image unknownImage;
    private Image logoImage;
    private Image tinyLogoImage;
    private Image rotateRightImage;
    private Image rotateLeftImage;
    private Image photosetOverlayImage;

    private Color friendsColor;
    private Color familyColor;
    private Color privateColor;
    private Color publicColor;
    private Color tagColor;
    private Color descriptionColor;
    private Color titleColor;

    private Color thumbnailBorderColor;
    private Color thumbnailBackgroundColor;
    private Color thumbnailSelectedBackgroundColor;
    private Color tagBorderColor;
    private Color disabledTextColor;
    private Color whiteColor;
    private Color blackColor;
    private Color aboutDialogFontColor;
    private Color progressBarColor;
    private Font authorizeHeaderFont;
    private Font authorizationFooterFont;
    private Font thumbnailDecorationFont;

    /**
     * 
     */
    public DefaultReusableUIFactory() {
        boolean runSleak = Boolean.getBoolean("sleak");
        if (runSleak) {
            DeviceData data = new DeviceData();
            data.tracking = true;
            display = new Display(data);
            new Sleak().open();
        } else
            display = new Display();
        initializeElements();
    }

    private void initializeElements() {
        initializeImages();
        initializeColors();
        initializeFonts();
    }

    private void initializeFonts() {
        FontData thumbnailDecorationFd = new FontData("Sans", 9, SWT.NORMAL);
        thumbnailDecorationFont = new Font(display, thumbnailDecorationFd);

        FontData authFD = new FontData("Sans", 14, SWT.BOLD);
        authorizeHeaderFont = new Font(display, authFD);

        FontData footerFontFD = new FontData("Sans", 9, SWT.NORMAL);
        authorizationFooterFont = new Font(display, footerFontFD);
    }

    private void initializeColors() {
        friendsColor = new Color(display, 128, 32, 32);
        familyColor = new Color(display, 128, 32, 32);
        privateColor = new Color(display, 166, 0, 0);
        publicColor = new Color(display, 0, 158, 59);
        tagColor = new Color(display, 0, 89, 168);
        descriptionColor = new Color(display, 0, 89, 168);
        titleColor = new Color(display, 0, 89, 168);
        aboutDialogFontColor = new Color(display, 100, 100, 100);
        thumbnailBorderColor = new Color(display, 180, 180, 180);
        thumbnailBackgroundColor = new Color(display, 250, 250, 250);
        thumbnailSelectedBackgroundColor = new Color(display, 0, 110, 220);
        tagBorderColor = new Color(display, 220, 220, 220);
        disabledTextColor = new Color(display, 180, 180, 180);
        progressBarColor = new Color(display, 0, 138, 255);

        whiteColor = new Color(display, 255, 255, 255);
        blackColor = new Color(display, 0, 0, 0);
    }

    private void initializeImages() {
        logoImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(LOGO_RESOURCE));
        tinyLogoImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(TINYLOGO_RESOURCE));

        uploadingImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(
                UPLOADING_RESOURCE));
        uploadedImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(UPLOADED_RESOURCE));
        unknownImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(UNKNOWN_RESOURCE));
        rotateRightImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(
                ROTATE_RIGHT_IMAGE));
        rotateLeftImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(
                ROTATE_LEFT_IMAGE));
        photosetOverlayImage = new Image(display, this.getClass().getClassLoader().getResourceAsStream(
                PHOTOSET_IMAGE));
    }

    public void dispose() {
        disposeImages();
        disposeColors();
        disposeFonts();
        display.dispose();
    }

    private void disposeFonts() {
        thumbnailDecorationFont.dispose();
        authorizeHeaderFont.dispose();
        authorizationFooterFont.dispose();
    }

    private void disposeColors() {
        friendsColor.dispose();
        familyColor.dispose();
        privateColor.dispose();
        publicColor.dispose();
        tagColor.dispose();
        descriptionColor.dispose();
        titleColor.dispose();
        disabledTextColor.dispose();
        thumbnailBorderColor.dispose();
        thumbnailBackgroundColor.dispose();
        thumbnailSelectedBackgroundColor.dispose();
        tagBorderColor.dispose();

        progressBarColor.dispose();

        whiteColor.dispose();
        aboutDialogFontColor.dispose();
        blackColor.dispose();
    }

    private void disposeImages() {
        logoImage.dispose();
        tinyLogoImage.dispose();
        uploadingImage.dispose();
        uploadedImage.dispose();
        unknownImage.dispose();
        rotateLeftImage.dispose();
        rotateRightImage.dispose();
        photosetOverlayImage.dispose();
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getDisplay()
     */
    public Display getDisplay() {
        return display;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getUploadingImage()
     */
    public Image getUploadingImage() {
        return uploadingImage;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getUploadedImage()
     */
    public Image getUploadedImage() {
        return uploadedImage;
    }

    public Image getPhotosetOverlayImage() {
        return photosetOverlayImage;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getFriendsColor()
     */
    public Color getFriendsColor() {
        return friendsColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getFamilyColor()
     */
    public Color getFamilyColor() {
        return familyColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getPrivateColor()
     */
    public Color getPrivateColor() {
        return privateColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getPublicColor()
     */
    public Color getPublicColor() {
        return publicColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getThumbnailBorderColor()
     */
    public Color getThumbnailBorderColor() {
        return thumbnailBorderColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getThumbnailBackgroundColor()
     */
    public Color getThumbnailBackgroundColor() {
        return thumbnailBackgroundColor;
    }

    public Color getAboutDialogFontColor() {
        return aboutDialogFontColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getThumbnailSelectedBackgroundColor()
     */
    public Color getThumbnailSelectedBackgroundColor() {
        return thumbnailSelectedBackgroundColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getTagColor()
     */
    public Color getTagColor() {
        return tagColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getDescriptionColor()
     */
    public Color getDescriptionColor() {
        return descriptionColor;
    }

    /**
     * @see org.scohen.juploadr.ui.ReusableUIFactory#getTitleColor()
     */
    public Color getTitleColor() {
        return titleColor;
    }

    public Color getWhiteColor() {
        return whiteColor;
    }

    public Color getBlackColor() {
        return blackColor;
    }

    public Color getTagBorderColor() {
        return tagBorderColor;
    }

    public Color getProgressBarColor() {
        return progressBarColor;
    }

    public Font getThumbnailDecorationFont() {
        return thumbnailDecorationFont;
    }

    public Image getLogoImage() {
        return logoImage;
    }

    public Color getDisabledTextColor() {
        return disabledTextColor;
    }

    public Image getTinyLogoImage() {
        return tinyLogoImage;
    }

    public Image getUnknownImage() {
        return unknownImage;
    }

    /**
     * @return Returns the authorizeHeaderFont.
     */
    public Font getAuthorizeHeaderFont() {
        return authorizeHeaderFont;
    }

    public Font getAuthorizationFooterFont() {
        return authorizationFooterFont;
    }

    /**
     * @return Returns the rotateLeftImage.
     */
    public Image getRotateLeftImage() {
        return rotateLeftImage;
    }

    /**
     * @return Returns the rotateRightImage.
     */
    public Image getRotateRightImage() {
        return rotateRightImage;
    }
}
